// 04myCenter/03receiveAddress/03receiverAddress.js
var co = require('../../resource/js/common.js')
var app = getApp()
var _this, _data, _opt
Page({
   /**
    * 页面的初始数据
    */
   data: {
      personalAddress: [], //用户地址列表
      hint: true,
      noNull: false,
   },
   /**
    * 生命周期函数--监听页面加载
    */
   onLoad: function(options) {
      _this = this
      _data = this.data
      this.getBizList()
   },
   //获取用户地址
   getPersonalAddress: function() {
      var userInfo = app.Data.userInfo
      var url = 'address/Addrmg/address'
      var param = {
         User_ID: userInfo.User_ID
      }
      var addressList = []
      co.getShareApi(url, param, function(res) {
         if (res.code == 0) {
            //console.log('res...',res)
            addressList = _data.personalAddress.concat(res.data)
            _this.setData({
               personalAddress: addressList,
               hint: false
            })
            //console.log('res.data==', res.data)
         } else {

         }
      })
   },
   //添加新地址
   addNewAddress: function() {
      wx.navigateTo({
         url: '/04myCenter/03receiveAddress/01newReceiveAddress/newReceiveAddress',
      })
   },
   //修改地址
   changePersonalAddress: function(e) {
      var index = e.currentTarget.dataset.index
      var Address_ID = e.currentTarget.dataset.address_id
      wx.navigateTo({
         url: '/04myCenter/03receiveAddress/02changeReceiveAddress/changeReceiveAddress?index=' + index + '&Address_ID=' + Address_ID
      })
   },
   //获取商家列表
   getBizList: function() {
      var url = 'jyhs/Admin/getBizList'
      co.getShareApi(url, {
         User_ID: app.Data.userInfo.User_ID
      }, function(res) {
         if (res.code == 0) {
            _this.setData({
               noNull: true
            })
         } else {

         }
      })
   },
   //跳转到企业收货地址
   toRecevingAddress: function() {
      wx.navigateTo({
         url: '/04myCenter/03receiveAddress/03enterpriseAddress/enterpriseAddress',
      })
   },
   onShow: function() {
      this.setData({
         personalAddress: []
      })
      this.getPersonalAddress()
   }
})